<template>
  <div>
    <el-dialog
      title="巡查任务记录"
      :visible="dialogVisible"
      custom-class="custom-dialog"
      :before-close="handleClose"
      @open="initData"
      width="78%"
      class="dialogClass"
    >
      <div class="page-container">
        <div class="table-container">
          <div class="table-tools-panel table-flex-row">
            <el-button class="flush-btn" size="mini" icon="el-icon-refresh"
              >刷新</el-button
            >
            <div>
              <el-button
                class="tools-btn"
                size="mini"
                icon="el-icon-set-up"
              ></el-button>
              <el-button
                class="tools-btn"
                size="mini"
                icon="el-icon-share"
              ></el-button>
              <el-button
                class="tools-btn"
                size="mini"
                icon="el-icon-printer"
              ></el-button>
            </div>
          </div>
          <div class="table-list-panel">
            <el-table
              v-loading="tableLoading"
              border
              size="small"
              :data="tableData"
              :height="isShow ? 'calc(100vh - 410px)' : 'calc(100vh - 335px)'"
              style="width: 100%"
            >
              <el-table-column type="selection" width="45" />
              <el-table-column
                prop="creatDeptName"
                label="办理部门"
                show-overflow-tooltip
              />
              <el-table-column
                prop="creatUserName"
                label="办理人"
                show-overflow-tooltip
              />
              <el-table-column
                prop="sourceName"
                label="来源名称"
                show-overflow-tooltip
              />
              <el-table-column prop="startTime" label="巡检时间" width="260">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.startTime }}
                  </div></template
                >
              </el-table-column>
              <el-table-column
                prop="categoryCompleteName"
                label="所属权责清单"
                show-overflow-tooltip
              />
              <el-table-column
                prop="nodeName"
                label="节点名称"
                show-overflow-tooltip
              />
              <el-table-column
                prop="nodeOpinion"
                label="节点处理意见"
                width="100"
                show-overflow-tooltip
              />
              <el-table-column
                prop="title"
                label="标题"
                show-overflow-tooltip
              />
              <el-table-column label="操作" width="90">
                <template slot-scope="scope">
                  <!-- <el-button
                    class="table-inner-btn"
                    type="text"
                    size="mini"
                    @click.native="handleDetail(scope.row)"
                    >详情</el-button
                  > -->
                  <el-button
                    class="table-inner-btn"
                    type="text"
                    size="mini"
                    @click.native="handleUpdate(scope.row)"
                    >详情</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="pagination-panel">
            <Pagination
              :total="query.total"
              :page.sync="query.pageNum"
              :limit.sync="query.pageSize"
              @pagination="initData"
            />
          </div>
        </div>

        <!-- <InspectionItemDetailsDialog
          :dialogVisible="DetailsDialog"
          :caseId="caseId"
          @closeDialog="DetailsDialog = false"
        /> -->
      </div>
    </el-dialog>
  </div>
</template>
<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import { getReportList } from "@/api/system/inspectionItemRecord";
import { parseTime } from "@/utils/index";
// import InspectionItemDetailsDialog from "./inspectionItemDetailsDialog";
import { detailsUrl } from "@/utils/changeUrl";
import moment from "moment";

import {
  deptEfficiency,
  deptEfficiencyDetailed
} from "@/api/system/doubleRandomMatters";

export default {
  name: "CaseDealDispatch",
  components: {
    SearchPanel,
    Pagination
    // InspectionItemDetailsDialog
  },
  data() {
    return {
      query: {
        total: 0,
        pageNum: 1,
        pageSize: 10
      },
      tableLoading: false,
      DetailsDialog: false,
      tableData: [],
      department: [],
      isShow: true
    };
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    taskId: {
      type: Object,
      default: {}
    }
  },
  created() {
    this.initData();
  },
  watch: {
    taskId(val) {
      if (val.type == "bumen") {
        this.query.deptId = val.deptId;
        this.query.flag = val.flag;
        this.select();
      } else if (val.type == "geren") {
        this.query.flag = val.flag;
        this.query.userId = val.userId;
        this.select();
      }
    }
  },
  methods: {
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    handleClose() {
      this.$emit("closeDialog");
    },
    parseTime,
    initData() {
      this.select();
    },
    select() {
      this.tableLoading = true;
      deptEfficiencyDetailed(this.query)
        .then(result => {
          this.tableLoading = false;
          this.tableData = result.rows;
          this.query.total = result.total;
          this.tableData.forEach(item => {
            item.startTime = moment(item.startTime).format(
              "YYYY-MM-DD HH:mm:ss"
            );
          });
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    handleUpdate(val) {
      let href_url = location.href;
      let url = href_url.match(/access_token=(\S*)&expireTime/)[1];
      let addressUrl = `${detailsUrl}/km/review/km_review_main/kmReviewMain.do?access_token=${url}&method=view&fdId=${
        val.id
      }`;
      window.open(addressUrl);
    }
  }
};
</script>

<style lang="scss" scoped>
.pagination-container {
  margin-top: 5px;
}
</style>
